package rd.hardcore.ui.config.content.boards 
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import rd.hardcore.engine.datas.streamBoard.StreamBoardEvent;
	import rd.hardcore.engine.datas.StreamBoardManager;
	import rd.hardcore.engine.tools.scrollable.ScrollManager;
	import rd.hardcore.ui.config.content.BaseContent;
	
	/**
	 * Config tab for Stream Pads
	 * @author Romain Prache
	 */
	public class BoardsContent extends BaseContent
	{
		private var container : Sprite;
		
		public function BoardsContent() 
		{
			container = new Sprite();
			
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			var _scroll:ScrollManager = new ScrollManager( container );
			_scroll.rect = new Rectangle( 0, 0, 500, 160 );
			
			
			addChild(_scroll);
			_scroll.activeScroll();
			_scroll.y = 50;
		}
		
		
		override public function build( _xml : XML ):void
		{
			super.build(_xml);
			
			if (StreamBoardManager.instance.STATE == StreamBoardManager.STREAM_BOARD_READY) {
				generate();
			}else {
				StreamBoardManager.instance.addEventListener(StreamBoardEvent.BOARD_READY_TO_DISPLAY, generate);
			}
		}
		
		private function generate(e:Event = null):void
		{
			var data : XML = StreamBoardManager.instance.getBoardsState();
			
			var i : int = 0;
			
			for each( var node : XML in data.children() )
			{
				var item : BoardItem = new BoardItem();
				item.build( node );
				container.addChild(item);
				
				item.x = ( (i % 2)		* ( 230)  	) >> 0;
				item.y = ( int(i / 2)	* ( 160) 	) >> 0;
				
				i++;
			}
			
			trace("CCONTAIONER  " + container.width + " :: " + container.height);
			
		}
		
		
		
	}

}